<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function loopString(str) {
            const len = str.length;
            let time = 0;
            return function () {
                if (time < len) {
                    console.log(str[time]);
                    // console.log(`${len} + ${time}`)
                    time++;
                    // return str[time];
                } else {
                    time = 0;
                    console.log(str[time]);
                    time++;
                    // console.log(str[time]);
                    // return str[time];
                }
            }
        }
        const ac = loopString('ac');
        ac();
        ac();
        ac();
        ac()
    </script>
</body>

</html>